$(function() {
    initNav();


    let userid = getCookie("userid");
    let token = getCookie("token");

    // 请求购物车数据; 
    function init() {

        var options = {
            url: "http://127.0.0.1:8888/cart/list",
            type: "GET",
            data: {
                id: userid
            },
            headers: {
                authorization: token
            },
            dataType: "json"
        };

        $.ajax(options)
            .done(function(res) {
                render(res);
            })
    }

    function render(res) {
        console.log(res.cart);
        $(".sp").html(
            res.cart.map(item =>
                `<tr id="list-l" class="" ispoint="0" name="499" pointamt="0"  >
                            <td> <label class="mn-check checks"></label></td>
                            <td>
                                <div class="cart-table-product">
                                    <div class="cart-table-img">
                                        <a href="./Details.html#id=${item.goods_id}"> <img src="${item.img_small_logo}"></a>
                                    </div>
                                    <div class="cart-table-name"><a href="./Details.html#id=${item.goods_id}">${item.title}</a></div>
                                </div>
                            </td>
                            <td class="price" data-pointpay="0">￥${item.price}</td>
                            <td>
                                <div class="cart-table-number"><a href="" class="add-product">+</a><input name="BuyNum" value="${item.cart_number}" disabled="disabled" type="text"><a href="" class="cut-product">-</a></div>
                            </td>
                            <td class="a-price">￥${ item.cart_number * item.price}</td>
                            <td><a class="delete" href="javascript:void(0)"><i class="icon-delete" data-id=${ item.goods_id} ></i>删除</a></td>
                        </tr>
                       `
                // `<div class="goods">
                //               <div class="p-goods">
                //                     <div class="p-img">
                //                           <img src="${item.img_small_logo}" alt="">
                //                     </div>
                //                     <div class="p-item">
                //                           ${item.title}
                //                     </div>
                //               </div>
                //               <div class="p-price">
                //                     ￥${item.price}
                //               </div>
                //               <div class="p-quantity">
                //                     <div class="cartnum">
                //                           <button>-</button>
                //                           <input type="text" value=${item.cart_number}>
                //                           <button>+</button>
                //                     </div>
                //               </div>
                //               <div class="p-sum"> ￥${ item.cart_number * item.price}</div>
                //               <div class="p-options">
                //                     <a data-id=${ item.goods_id} href="javascript:void(0)">删除</a>
                //               </div>
                //         </div>`
            ).join("")
        )

    }
    init();

    function del() {

    }
});